const express = require('express')
const app = express()

const products = [
  {id: 1, name: 'AAA', price: 1212},
  {id: 2, name: 'BBB', price: 2323},
  {id: 3, name: 'CCC', price: 3434}
]
app.get('/products', (req, res) => {
  let liStr = ''
  // 遍历 products, 生成li标签, 并拼接到liStr
  products.forEach(p => {
    liStr += `<li>${p.id}-${p.name}-${p.price}</li>`
  })

  res.send(`
    <!DOCTYPE html>
    <html lang="en">
    <head>
      <meta charset="UTF-8">
      <meta http-equiv="X-UA-Compatible" content="IE=edge">
      <meta name="viewport" content="width=device-width, initial-scale=1.0">
      <title>Document</title>
    </head>
    <body>
      <h2>商品列表</h2>
      <ul>
        ${liStr}
      </ul>
    </body>
    </html>
  `)
})

app.listen('3000',  () => {
  console.log('服务已启动: http://localhost:3000')
})